#include "Tool.h"
#include <QTime>
#include <QCoreApplication>
#include <QDateTime>
#include <QApplication>
#include <QDesktopWidget>
#include <QFile>
#include <QTextStream>

Tool::Tool()
	: QObject()
{

}

Tool::~Tool()
{

}

void Tool::delayTime(int milSec)
{
	QTime dieTime = QTime::currentTime().addMSecs(milSec);
	while(QTime::currentTime()<dieTime)
	{
		QCoreApplication::processEvents(QEventLoop::AllEvents,100);
	}
}

QString Tool::SystemTime()
{
	QString currentDate;

	QDateTime dt;
	QTime time;
	QDate date;

	dt.setTime(time.currentTime());
	dt.setDate(date.currentDate());

	currentDate = dt.toString("hh:mm:ss:zzz");

	return currentDate;
}


int Tool::ScreenHeight()
{ 
	return QApplication::desktop()->height(); 
}

int Tool::ScreenWidth()
{
	return QApplication::desktop()->width(); 
}


void Tool::writeLog(QString mess)
{
	QFile file("my_log.log");
	if(!file.open(QIODevice::Append))
	{
		return;
	}
	QTextStream out(&file);
	out<<mess;
	out<<"\n";
	file.close();
}

void Tool::writeLogChar(char *mess ,qint64 size)
{
	QByteArray tmp(mess,size);
	QFile file("my_log.log");
	if(!file.open(QIODevice::Append))
	{
		return;
	}
	QTextStream out(&file);
	for(int i=0;i<size; i++)
	{
		int  tint = mess[i];
		QString tmp;
		tmp.setNum(tint); 
		out<<tmp;
		out<< " ";
	}
	out<<"\n";
	
	file.close();
}
